package com.xidian.zhiancloud.controller.systemset;

import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.syset.UserDetails;
import com.xidian.zhiancloud.service.user.UserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户-基本设置
 */
@RestController
@RequestMapping("/userdeta")
public class UserDetailsController extends BaseController {

    @Autowired
    UserDetailsService userDetailsService;

    @RequestMapping("/getUserDetailsList")
    public ResultDTO getUserDetailsList(@RequestParam("userId") String userId){
        Long companyId = this.getSessionUserCompanyId();
        List<UserDetails> userDetailsList = userDetailsService.getUserDetailsList(userId,companyId);
        return ResultDTO.successOf(userDetailsList,GeneralResponseEnums.SUCCESS);
    }

    @RequestMapping("/updateUserDetails")
    public ResultDTO updateUserDetails(@RequestParam("userId") String userId,UserDetails userDeta){
        Long companyId = this.getSessionUserCompanyId();
        List<UserDetails> userDetailsList = userDetailsService.getUserDetailsList(userId,companyId);
        Map<String,Object> in = new HashMap<String, Object>();
        if (userDetailsList.size()>0) {
            in.put("userId", userId);
            in.put("phone", userDeta.getPhone());
            in.put("idCard", userDeta.getIdCard());
            in.put("gender", userDeta.getGender());
            in.put("techTitle", userDeta.getTechTitle());
            in.put("writeTitle", userDeta.getWriteTitle());
            in.put("school", userDeta.getSchool());
            in.put("major", userDeta.getMajor());
            in.put("education", userDeta.getEducation());
            in.put("entryDate", userDeta.getEntryDate());
            in.put("arrivalDate", userDeta.getArrivalDate());
            in.put("profilePath", userDeta.getProfilePath());
            userDetailsService.updateUserDetails(userId,in);
        }else if (userDetailsList.size()==0) {
            in.put("companyId", companyId);
            in.put("userId", userId);
            in.put("phone", userDeta.getPhone());
            in.put("idCard", userDeta.getIdCard());
            in.put("gender", userDeta.getGender());
            in.put("techTitle", userDeta.getTechTitle());
            in.put("writeTitle", userDeta.getWriteTitle());
            in.put("school", userDeta.getSchool());
            in.put("major", userDeta.getMajor());
            in.put("education", userDeta.getEducation());
            in.put("entryDate", userDeta.getEntryDate());
            in.put("arrivalDate", userDeta.getArrivalDate());
            in.put("profilePath", userDeta.getProfilePath());
            in.put("createId", userDeta.getCreateId());
            userDetailsService.addUserDetails(userId,in);
        }
        return ResultDTO.successOf(userDetailsList,GeneralResponseEnums.SUCCESS);
    }
    
    
}
